// pages/registerUser/registerUser.js
const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {

    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    },

    formSubmit(event) {    
      var that = this;
      var role = event.detail.value.role;
      var name = event.detail.value.name;
      var age = event.detail.value.age;
      var phoneNumber = event.detail.value.phoneNumber;
      wx.request({
        url: app.globalData.base_request + "/other/registerUser/" + role + "/" + app.globalData.userId + "/" + name + "/" + age + "/" + phoneNumber,
        method: 'GET',
        success(res) {
          console.log('success');
          console.log(res.data);
          wx.showToast({  
              title: res.data,  
              icon: 'loading',  
              duration: 2000  
          });
          if(res.data == 'success')
          {
            app.communityHospitalRegistered = true;
            if(role == 0)
            {
              app.communityHospitalRole = 'patient';
            }
            if(role == 1)
            {
              app.communityHospitalRole = 'doctor';
            }
            console.log(app.globalData.communityHospitalRegistered);
            console.log(app.globalData.communityHospitalRole);
          }
          wx.navigateTo({
            url: '../communityHospitalIndex/communityHospitalIndex',
          })
        },
        fail: function() {
          console.log("failure");  
          wx.showToast({  
              title: '无法连接服务器',  
              icon: 'loading',  
              duration: 2000  
          });
          wx.navigateTo({
            url: '../communityHospitalIndex/communityHospitalIndex',
          })
        }
      });
    }
})